
<form class="layui-form pt10" action="{:url()}" method="post" id="editForm">
    <div class="layui-form-item">
        <label class="layui-form-label">会员</label>
        <div class="layui-input-inline">

            <select name="user_id" class="layui-input field-user_id" lay-verify="required" lay-search="">
              <option value="">直接选择或搜索选择</option>
              {$users|raw}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">产品名称</label>
        <div class="layui-input-inline">
            <select name="product_id" class="layui-input field-product_id" lay-verify="required" lay-search="" lay-filter="selectProduct">
              <option value="">直接选择或搜索选择</option>
              {$products|raw}
            </select>
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">仓库</label>
        <div class="layui-input-inline">
            <select name="warehouse_id" class="layui-input field-warehouse_id" lay-verify="required" lay-search="" lay-filter="">
                <option value="">直接选择或搜索选择</option>
                {$warehouses|raw}
              </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">负责人</label>
        <div class="layui-input-inline">
            <select name="admin_id" class="layui-input field-admin_id" lay-verify="required" lay-search="">
              <option value="">直接选择或搜索选择</option>
              {$admins|raw}
            </select>
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>  


    <div class="layui-form-item">
        <label class="layui-form-label">数量</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-num" id="num" name="num" value="1" lay-verify="number|required" autocomplete="off" >
        </div>
    </div>

    <input type="hidden" class="layui-input field-address" value="直接寄存" name="address" lay-verify="" autocomplete="off" ">
    <!-- <div class="layui-form-item">
        <label class="layui-form-label">存放位置</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-address" value="直接寄存" name="address" lay-verify="" autocomplete="off" ">
        </div>
    </div> -->
    <!-- <input type="hidden" class="layui-input field-unit_price" name="unit_price" id="unit_price"> -->
    <div class="layui-form-item">
        <label class="layui-form-label">产品单价</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-price1" name="price1" id="price1" lay-verify="" autocomplete="off" ">
        </div>
    </div> 
    <div class="layui-form-item">
        <label class="layui-form-label">产品总价</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-price" name="price" id="price" lay-verify="" autocomplete="off" ">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-bak" name="bak" lay-verify="" autocomplete="off" ">
        </div>
    </div>

    <input type="hidden" class="field-shop_id" name="shop_id" value="{:session('shop_id')}">

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" class="field-sn" name="sn" value="{:create_order_sn()}">
            <input type="hidden" class="field-id" name="id">
        </div>
    </div>
    <div class="pop-bottom-bar hisi-footer">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: true}">提交保存</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>
<!-- <script src="__PUBLIC_JS__/layui/xm-select.js" charset="utf-8"></script> -->
{include file="system@block/layui" /}

<script>

layui.use(['func','laydate','form','jquery'], function() {
    //常规用法
    var laydate = layui.laydate;
    var form = layui.form
    var $ = layui.jquery
    laydate.render({
          elem: '#date',
          trigger:'click',
          type:'datetime'
        });


    layui.func.assign({:json_encode($formData)});

    form.on('select(selectProduct)', function (data) {
        var pid = data.value
        console.log(pid)
        $.ajax({
            url:"{:url('getProductPrice')}",
            type:'get',
            data:{pid:pid},
            success:function(res){
                $('#price1').val(res);
                $('#price').val(res * $('#num').val());
            }
        })
    });
    $(function(){
        $('#num').on('change',function(){
            var price = $('#price1').val() * $('#num').val()
            $('#price').val(price.toFixed(2));
        })
        $('#price1').on('change',function(){
            var price = $('#price1').val() * $('#num').val()
              $('#price').val(price.toFixed(2));
        })
        $('#price').on('change',function(){
          var price1 = $('#price').val() / $('#num').val()
            $('#price1').val(price1.toFixed(2));
        })
    })
});
</script>
